package chatin.client;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;

public class ContactListUI extends JPanel {
	
	private JList jList = null;
	private JPanel bottomPanel = null;
	private JButton logoutButton = null;
	private JComboBox contactListCB = null;
	private JPanel topPanel = null;
	private JLabel nameUserLabel = null;
	
	/**
	 * This method initializes 
	 * 
	 */
	public ContactListUI() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 */
	private void initialize() {
        this.setLayout(new BorderLayout());
        this.setSize(new Dimension(300, 200));
        this.add(getTopPanel(), BorderLayout.NORTH);
        this.add(getJList(), BorderLayout.CENTER);
        this.add(getBottomPanel(), BorderLayout.SOUTH);
	}

	/**
	 * This method initializes jList	
	 * 	
	 * @return javax.swing.JList	
	 */
	private JList getJList() {
		if (jList == null) {
			jList = new JList();
		}
		return jList;
	}

	/**
	 * This method initializes bottomPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getBottomPanel() {
		if (bottomPanel == null) {
			bottomPanel = new JPanel();
			bottomPanel.setLayout(new BorderLayout());
			bottomPanel.add(getContactListCB(), BorderLayout.CENTER);
			bottomPanel.add(getLogoutButton(), BorderLayout.EAST);
		}
		return bottomPanel;
	}

	/**
	 * This method initializes logoutButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getLogoutButton() {
		if (logoutButton == null) {
			logoutButton = new JButton();
			logoutButton.setText("Logout");
			logoutButton.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent arg0) {
					//try { ClientMediator.exec("UsersAccount.logout", new Object[] { username } ); } catch (XmlRpcException e) { e.printStackTrace(); }
					ChangerView.changeView(ChangerView.LOGIN);
			        ChangerView.getJFrame().setSize(250, 250);
				}
			});
		}
		return logoutButton;
	}

	/**
	 * This method initializes contactListCB	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getContactListCB() {
		if (contactListCB == null) {
			contactListCB = new JComboBox();
			contactListCB.setModel(new DefaultComboBoxModel(new String[] {
					"Disponível", "Ocupado", "Ausente", "Invisível" }));
		}
		return contactListCB;
	}

	/**
	 * This method initializes topPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getTopPanel() {
		if (topPanel == null) {
			topPanel = new JPanel();
			topPanel.setLayout(new FlowLayout());
			topPanel.add(getNameUserLabel(), null);
		}
		return topPanel;
	}

	/**
	 * This method initializes nameUserLabel	
	 * 	
	 * @return javax.swing.JLabel	
	 */
	private JLabel getNameUserLabel() {
		if (nameUserLabel == null) {
			nameUserLabel = new JLabel();
			nameUserLabel.setText("Nome do Usuário");
		}
		return nameUserLabel;
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"
